package de.lmu.ifi.pst.uwejsf.framework;

import java.util.Map;

import javax.script.ScriptContext;
import javax.script.ScriptEngine;

/**
 * Interface that must be implemented by Expression context providers that
 * provide a {@link ScriptEngine} and a {@link ScriptContext} as well
 * as some helper methods to access the web application context.
 * <p>
 * There's usually no need to create a custom implementation. The application
 * core uses a generated class that extends {@link AbstractUWEContextFactory} which 
 * in turn implements {@link ExpressionContextProvider} and provides a script context
 * for OGNL. The generated class also contains a mapping between UWE model class names and Java 
 * class names.  
 * </p>
 * 
 * @see https://scripting.dev.java.net/
 * @author Christian Kroiss
 */
public interface ExpressionContextProvider {
	
	/**
	 * Returns a map of all JSF managed beans indexed by their name.
	 */
	public Map<String, Object> getManagedBeans();

	/**
	 * Returns a {@link ScriptEngine} that is identified by the given name.
	 * @param name the name of the script engine.
	 * @return
	 */
	public ScriptEngine getScriptEngineByName(String name);
	
	/**
	 * Returns a {@link ScriptContext} that uses the given context object
	 * as root.
	 * 
	 * @param contextObject the object to use as root for the script context.
	 * @return the created script context.
	 */
	public ScriptContext createScriptContext(Object contextObject);
	
	/**
	 * Returns the qualified UWE model class name that corresponds to
	 * the given full qualified Java class name.
	 * @param applicationTypeName a full qualified Java class name.
	 * @return a qualified UWE model class name.
	 */
	public String getTypeMapping(String applicationTypeName);
	
	/**
	 * Returns the full qualified Java class name that corresponds to the given
	 * qualified UWE model class name.
	 * @param contentModelName a qualified UWE model class name.
	 * @return a full qualified Java class name.
	 */
	public String getReverseTypeMapping(String contentModelName);
	
	/**
	 * Returns the instance of the application's persistence manager
	 * that is used for this session.
	 */
	public PersistenceManager getPersistenceManager();
	
}
